package cn.edu.stu.syllabus.widgets;

import android.view.View;

/**
 * Created by liyujie on 2017/3/17.
 */

public abstract class DoubleClickListener implements View.OnClickListener {

    private static final int DOUBLE_CLICK_TIME = 1000;

    public abstract void onDoubleClick();

    private long lastClickTime = 0;

    @Override
    public void onClick(View v) {
        long thisClickTime = System.currentTimeMillis();
        if (thisClickTime - lastClickTime < DOUBLE_CLICK_TIME) {
            resetClick();
            onDoubleClick();
        } else {
            lastClickTime = thisClickTime;
        }
    }

    private void resetClick() {
        lastClickTime = 0;
    }
}
